package sde.actor.eratostene;
import sde.actor.*;
public class Filtro extends Actor implements FiltroIF{
	private int primo;
	private Filtro out;
	private static int conta=0;
	public Filtro( int primo ){ this.primo=primo; }
	public void handler( Message m ){
		if( m instanceof Number ){
			int x=((Number)m).getNumber();
			if( x==0 ){
			   System.out.printf( "%6d", primo );
			   conta++;
			   if( conta%12==0 || out==null ) 
				System.out.println();
			   if( out!=null ) out.send( m ); //propaga numero
			   return;
			}
			if( x%primo==0 ) return;
			if( out!=null ) out.send( m );
			else out=new Filtro( x );
		}
	}//handler
}//Filtro

